﻿//===================================================================================
// $$
//
//
// Code By: Code Milker V2
// Date On: 2013//
//===================================================================================


namespace Forest.Lion.Data.SqlServer.Repositories
{
    using System;

    using System.Collections.Generic;

    using System.Data;

    using System.Linq;
    using Forest.Lion.Model;

    public class SkillRepository : BaseRepository, ISkillRepository
    {
        public SkillRepository(IUnitOfWork unitOfWork)
            : base(unitOfWork)
        {
        }
        public void Create(Skill skill)
        {
            this.GetDbSet<Skill>().Add(skill);
            this.UnitOfWork.SaveChanges();
        }

        public Skill GetSkill(Guid skillId)
        {
            return this.GetDbSet<Skill>()
                .Where(c => c.Id == skillId)
                .Single();
        }

        public void Update(Skill updatedSkill)
        {
            this.GetDbSet<Skill>().Attach(updatedSkill);
            this.SetEntityState(updatedSkill, updatedSkill.Id == Guid.Empty
                ? EntityState.Added
                : EntityState.Modified);
            this.UnitOfWork.SaveChanges();
        }

        public void Delete(Guid skillId)
        {
            Skill skillToDelete = this.GetSkill(skillId);
            this.GetDbSet<Skill>().Remove(skillToDelete);
            this.UnitOfWork.SaveChanges();
        }

        public IEnumerable<Skill> Find()
        {
            return this.GetDbSet<Skill>().Take(100)
                .ToList();
        }

        public IEnumerable<Skill> GetAll()
        {
            return this.GetDbSet<Skill>().Take(100)
                .ToList();
        }
    }
}
